export default {
    data() {
        return {
            form:{
                    bab010: {
                        value: '',
                        p: 'R'
                    },
                    aab069: {
                        value: '',
                        p: 'R'
                    },
                    aab301: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aaa027: {
                        value: '',
                        p: 'D'
                    },
                    aab021: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aab023: {
                        key: '',
                        value: '',
                        p: 'E'
                    },
                    aaa149: {
                        key: '',
                        value: '',
                        p: 'E'
                    },
                    aab000: {
                        value: '',
                        p: 'R'
                    },
                    bae566: {
                        value: '',
                        p: 'E'
                    },
                    bae567: {
                        value: '',
                        p: 'E'
                    },
                    czphone: {
                        value: '',
                        p: 'E'
                    },
                    dwaae159: {
                        value: '',
                        p: 'E'
                    },
                    aae007: {
                        value: '',
                        p: 'E'
                    },
                    bae011: {
                        key: '',
                        value: '',
                        p: 'E'
                    },
                    bae012: {
                        key: '',
                        value: '',
                        p: 'E'
                    },
                    bae013: {
                        key: '',
                        value: '',
                        p: 'E'
                    },
                    aae006: {
                        value: '',
                        p: 'E'
                    },
                    lx: {
                        value: '',
                        p: 'H'
                    },
                    aae011: {
                        value: '',
                        p: 'R'
                    },
                    lxrlx: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    lxraac002: {
                        value: '',
                        p: 'R'
                    },
                    aae005: {
                        value: '',
                        p: 'R'
                    },
                    aac067: {
                        value: '',
                        p: 'R'
                    },
                    aaa082: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aaf200: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aaf002: {
                        value: '',
                        p: 'R'
                    },
                    bac049: {
                        value: '',
                        p: 'D'
                    },
                    aae009: {
                        value: '',
                        p: 'R'
                    },
                    aae010: {
                        value: '',
                        p: 'R'
                    },

            },
            tableData1: {},
            tableData1Id: {},
            activeNames:['1'],
            panel: {},
            rules:{

                bab010: [
                    {required: true,validator:this.$localRules.checkBAB010, trigger: 'blur'}
                ],
                aab001: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aab069: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aab019: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aab020: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aab021: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aab013: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                bank: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                banklb: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                bankno: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                bankname: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                cardname: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                cardno: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aae007: [
                    { validator: this.$rules.postcode, trigger: 'blur'}

                ],
                dwaae159: [
                    { validator: this.$rules.isEmail, trigger: 'blur'}

                ],
                aae159: [
                    { validator: this.$rules.isEmail, trigger: 'blur'}

                ],
                aac147: [
                    { validator: this.$rules.isIDCard, trigger: 'blur'}

                ],
                czphone: [
                    {validator: this.$rules.telephone, trigger: 'blur'}

                ],
                aae005: [
                    {validator: this.$rules.telephone, trigger: 'blur'}

                ],
                bae566: [
                    {validator: this.$rules.telephone, trigger: 'blur'}

                ],
                bae567: [
                    {validator: this.$rules.mobile, trigger: 'blur'}

                ],
                aac067: [
                    {validator: this.$rules.mobile, trigger: 'blur'}

                ],
                aaa082:  [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aaf200:  [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aaf002:[
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                bac049:  [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aae009: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aae010: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aab301: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                aae011: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                lxrlx: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],
                lxraac002: [
                    {required: true,validator:this.$localRules.isRequired,message: '必填项，不能为空'}
                ],

            },
            codeTypes:{
                AAB006:[],
                AAB019:[],
                AAB020:[],
                AAB021:[],
                AAB023:[],
                AAB022:[],
                AAA149:[],
                BAE007: [],
                BAE008: [],
                BAE009: [],
                AAB301:[],
                AAC058:[],
                AAA082:[],
                AAF200:[],
                AAF002:[],
                AAE140:[],
                AAZ289:[],
                AAB033:[],

            },
            codeTypeFilters:{

            },
            pager: {
                page: 1,
                size: 10
            },
            total: 0,
        }
    },
    computed: {
        functionId() {
            if (this.$store.getters.init.path !== this.$route.path) return;
            if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
            if (this.$store.getters.init.mdParam.functionid === undefined) return;
            return this.$store.getters.init.mdParam.functionid;
        },
        backFun() {
            return this.$store.getters.backFun;
        },
        init_formData() {
            if (this.$store.getters.init.path !== this.$route.path)  return;
            return this.$store.getters.init.form;
        },
        init_panel() {
            if (this.$store.getters.init.path !== this.$route.path)  return;
            return this.$store.getters.init.panel;
        },
        doInitpanel: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.panel;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        doInitformData: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.formData;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },


        init_tableData1() {
            return this.$store.getters.init.tableData1;
        },
        doInittableData1: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData1;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },
        init_tableData1Id() {
            return this.$store.getters.init.tableData1Id;
        },
        doInittableData1Id: {
            get: function () {
                if (this.$store.getters.common === null) return [];
                if (this.$store.getters.common.path !== this.$route.path) return;
                return this.$store.getters.common.tableData1Id;
            },
            set: function (newValue) {
                if (newValue.path !== this.$route.path) return;
                return newValue;
            }
        },

    },
    created() {
        let param = {
            path: this.$route.path,
            codeTypes:this.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            form:this.form,
            tableData1:this.tableData1,
            panel:this.panel
        };
        if (this.$route.query.keepAlive === undefined) {
            this.$store.dispatch('SET_INIT', param);
        }

    },
    watch: {
        init_formData: {
            handler(value) {
                if (value == undefined) return;
                this.getformData(value);
            },
            deep: true
        },
        doInitformData: {
            handler(value) {
                if (value == undefined) return;
                this.getformData(value);
            },
            deep: true
        },
        init_panel: {
            handler(value) {
                if (value == undefined) return;
                this.getpanel(value);
            },
            deep: true
        },
        doInitpanel: {
            handler(value) {
                if (value == undefined) return;
                this.getpanel(value);
            },
            deep: true
        },
        doInittableData1: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData1(value);
            },
            deep: true
        },
        doInittableData1Id: {
            handler(value) {
                if (value == undefined) return;
                this.gettableData1Id(value);
            },
            deep: true
        },

        backFun: {
            handler(value) {
                if (value === null) return;
                this.customBackFun();
                let backFun = [];
                backFun = value.split(',');
                if (backFun.indexOf('rDoInit') >= 0) {
                    let codeTypes = {
                        AAB019:[],
                        AAB020:[],
                        AAB021:[],
                        AAB023:[],
                        AAB022:[],
                        AAA149:[],
                        BAE007:[],
                        AAB301:[],
                        LXRLX:[],
                        AAA082:[],
                        AAF200:[],
                        AAF002:[],
                        AAE140:[],

                    };
                    let panel= {};
                    let form = {
	                    bab010: {
	                        value: '',
	                        p: 'R'
	                    },
	                    aab069: {
	                        value: '',
	                        p: 'R'
	                    },
	                    aab301: {
	                        key: '',
	                        value: '',
	                        p: 'R'
	                    },
	                    aaa027: {
	                        value: '',
	                        p: 'D'
	                    },
	                    aab021: {
	                        key: '',
	                        value: '',
	                        p: 'R'
	                    },
	                    aab023: {
	                        key: '',
	                        value: '',
	                        p: 'E'
	                    },
	                    aaa149: {
	                        key: '',
	                        value: '',
	                        p: 'E'
	                    },
	                    aab000: {
	                        value: '',
	                        p: 'R'
	                    },
	                    bae566: {
	                        value: '',
	                        p: 'E'
	                    },
	                    bae567: {
	                        value: '',
	                        p: 'E'
	                    },
	                    czphone: {
	                        value: '',
	                        p: 'E'
	                    },
	                    dwaae159: {
	                        value: '',
	                        p: 'E'
	                    },
	                    aae007: {
	                        value: '',
	                        p: 'E'
	                    },
	                    bae011: {
	                        key: '',
	                        value: '',
	                        p: 'E'
	                    },
	                    bae012: {
	                        key: '',
	                        value: '',
	                        p: 'E'
	                    },
	                    bae013: {
	                        key: '',
	                        value: '',
	                        p: 'E'
	                    },
	                    aae006: {
	                        value: '',
	                        p: 'E'
	                    },
	                    lx: {
	                        value: '',
	                        p: 'H'
	                    },
	                    aae011: {
	                        value: '',
	                        p: 'R'
	                    },
	                    lxrlx: {
	                        key: '',
	                        value: '',
	                        p: 'R'
	                    },
	                    lxraac002: {
	                        value: '',
	                        p: 'R'
	                    },
	                    aae005: {
	                        value: '',
	                        p: 'R'
	                    },
	                    aac067: {
	                        value: '',
	                        p: 'R'
	                    },
	                    aaa082: {
	                        key: '',
	                        value: '',
	                        p: 'R'
	                    },
	                    aaf200: {
	                        key: '',
	                        value: '',
	                        p: 'R'
	                    },
	                    aaf002: {
	                        value: '',
	                        p: 'R'
	                    },
	                    bac049: {
	                        value: '',
	                        p: 'D'
	                    },
	                    aae009: {
	                        value: '',
	                        p: 'R'
	                    },
	                    aae010: {
	                        value: '',
	                        p: 'R'
	                    },
                    };
                    let tableData1= {};

                    let param = {
                        path: this.$route.path,
                        codeTypes:codeTypes,
                        codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                        form:form,
                        tableData1:tableData1,
                        panel:panel
                    };
                    this.$store.dispatch('SET_INIT', param);
                }
            }
        }
    },
    mounted() {
        if (this.$store.getters.cacheData === null) return;
        if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
        if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
        if (this.$store.getters.cacheData[this.$route.path].form !== undefined) {
            this.getformData(this.$store.getters.cacheData[this.$route.path].form);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData1 !== undefined) {
            this.gettableData1(this.$store.getters.cacheData[this.$route.path].tableData1);
        }
        if (this.$store.getters.cacheData[this.$route.path].tableData1Id !== undefined) {
            this.gettableData1Id(this.$store.getters.cacheData[this.$route.path].tableData1Id);
        }
        if (this.$store.getters.cacheData[this.$route.path].panel !== undefined) {
            this.getpanel(this.$store.getters.cacheData[this.$route.path].panel);
        }
    },
    beforeRouteLeave(to, from, next) {
        let param = {
            path: this.$route.path,
            codeTypes: this.$store.getters.codeTypes,
            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
            form:this.form,
            tableData1:this.tableData1,
            panel:this.panel
        };
        if (from) {
            this.$store.dispatch('SET_CACHEDATA', param);
        }
        next();
    },
    methods: {
        handleChange(val) {
            console.log(val);
        },
        getformData(value) {
            this.form = value;
        },
        getpanel(value) {
            this.panel = value;
        },
        gettableData1(value) {
            this.tableData1 = value;
        },
        gettableData1Id(value) {
            this.tableData1Id = value;
        },

        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        clear() {
            let codeTypes = {
                AAB019:[],
                AAB020:[],
                AAB021:[],
                AAB023:[],
                AAB022:[],
                AAA149:[],
                BAE007:[],
                AAB301:[],
                LXRLX:[],
                AAA082:[],
                AAF200:[],
                AAF002:[],
                AAE140:[],

            };
            let form = {
                bab010: {
                    value: '',
                    p: 'R'
                },
                aab069: {
                    value: '',
                    p: 'R'
                },
                aab301: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                aaa027: {
                    value: '',
                    p: 'D'
                },
                aab021: {
                    key: '',
                    value: '',
                    p: 'R'
                },
                aab023: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                aaa149: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                aab000: {
                    value: '',
                    p: 'R'
                },
                bae566: {
                    value: '',
                    p: 'E'
                },
                bae567: {
                    value: '',
                    p: 'E'
                },
                czphone: {
                    value: '',
                    p: 'E'
                },
                dwaae159: {
                    value: '',
                    p: 'E'
                },
                aae007: {
                    value: '',
                    p: 'E'
                },
                aae006: {
                    value: '',
                    p: 'E'
                },
                bae011: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                bae012: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                bae013: {
                    key: '',
                    value: '',
                    p: 'E'
                },
                lx: {
                    value: '',
                    p: 'H'
                },

            };
            let tableData1= {};

            let param = {
                path: this.$route.path,
                codeTypes:codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:form,
                tableData1:tableData1

            };
            this.$store.dispatch('SET_INIT', param);
        },

        handleEdit(id) {
            this.dialogFormVisible = true;
        },
        formValidate(value){
            if(value && value.length>0){
                let btn = true;
                value.forEach((item,index)=>{
                    if(!btn) return
                    this.$refs[item].validate((valid) => {
                        if (valid) {
                            btn = true;
                        } else {
                            btn = false;
                        }
                    });
                })
                if(btn) this.$refs.save.btn();
            }
        },
        customBackFun(){//自定义方法体
        },
    },
}
